package com.xaicode.auth.constant;

/**
 * 全局启用与禁用状态
 * 
 * @date 2024/12/19
 */
public enum EnableEnum {

    /**
     * 启用
     *
     * @see DataConst#ENABLE
     */
    ENABLE(0, "启用"),

    /**
     * 禁用
     *
     * @see DataConst#DISABLE
     */
    DISABLE(1, "禁用");


    private final int code;
    private final String desc;

    EnableEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static EnableEnum valueOf(Integer code) {
        if (code == null) {
            return null;
        }
        for (EnableEnum status : EnableEnum.values()) {
            if (status.code == code) {
                return status;
            }
        }
        return null;
    }

    public static String parseValue(Integer code) {
        if (code == null) {
            return null;
        }
        for (EnableEnum status : EnableEnum.values()) {
            if (status.getCode() == code) {
                return status.getDesc();
            }
        }
        return null;
    }

    public static Integer valueOfDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (EnableEnum status : EnableEnum.values()) {
            if (status.desc.equals(desc)) {
                return status.getCode();
            }
        }
        return null;
    }

    /**
     * 是否正常
     */
    public static boolean isEnable(Integer value) {
        if (value == null) {
            return false;
        }
        return ENABLE.getCode() == value;
    }

}
